<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <!-- 引入vue2的js文件 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.9/vue.js"></script>
</head>

<body>
    <div id="app">
        <p>水果:{{fruit}}</p>
        <button @click="change">点他吃新水果</button>
        <p v-for="item in books" :key="item.number">{{item.name}}—{{item.number}}
            <button @click="item.number++">点他加数量</button>
        </p>
    </div>

    <script>
        new Vue({
            el: '#app',
            data: {
                fruit: 'strawberry',
                books: [
                    { name: '水浒传', writer: '施耐庵', number: 1 },
                    { name: '西游记', writer: '吴承恩', number: 2 },
                ],
            },
            methods: {
                change() {
                    this.fruit = 'watermelon'
                },
            },
            watch: {
                fruit(newValue, oldValue) {
                    console.log('oldValue', oldValue);
                    console.log('newValue', newValue);
                },
                books: {
                    handler(newValue, oldValue) {
                        console.log('oldValue', oldValue);
                        console.log('newValue', newValue);
                    },
                    deep: true,
                    immediate: true
                }
            }
        })
    </script>
</body>

</html>